import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { ApiProperty, ApiHideProperty } from '@nestjs/swagger';
import { Book } from '../../book/entities/book.entity';

@Entity('categories')
export class Category {
  @ApiProperty({ description: '分类ID' })
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty({ description: '分类名称' })
  @Column({ unique: true })
  name: string;

  @ApiProperty({ description: '分类描述' })
  @Column('text', { nullable: true })
  description: string;

  @ApiProperty({ description: '排序顺序' })
  @Column('int', { default: 0 })
  sortOrder: number;

  @ApiProperty({ description: '是否启用' })
  @Column('boolean', { default: true })
  isActive: boolean;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn()
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn()
  updatedAt: Date;

  // 关联图书，一个分类可以有多本图书
  @ApiHideProperty()
  @OneToMany(() => Book, (book) => book.category)
  books: Book[];
}